package com.zdya.combatdocuments.util;

import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.http.HttpService;

import java.math.BigInteger;

public class EthWeb3JUtil {

    public static String getVersion(String address){
        Web3j web3j = Web3j.build( new HttpService( address ) );
        try {
            String v = web3j.netVersion().send().getNetVersion();

            Request<?, EthBlockNumber> ethBlockNumberRequest = web3j.ethBlockNumber();
            BigInteger blockNumber = ethBlockNumberRequest.send().getBlockNumber();
            System.out.println(blockNumber);


            return v;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }

    public static void main(String[] args) {
        System.out.println("***"+getVersion("http://192.168.3.215:8545"));
    }

}
